﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace JeanFish.UnitTest.Core
{
    [TestClass]
    public class CollectionHelperTest
    {
        [TestMethod]
        public void EachTest()
        {
            List<int> data = new List<int>();
            int total=100;
            for (int i = 0; i < total; i++)
                data.Add(i);
            int size=100;
            
            int step=0;
            int start = 0;
            int end = 99;
            int expected = start;
            int expectedtotal =end>(total-1)?total-start:end - start + 1;
            int count = 0;
            foreach (var ds in data.Each(size,start,end))
            {
                Assert.AreEqual(expected, ds.First());
                expected += size;
                step++;
                count += ds.Count();
            }
            Assert.AreEqual(Math.Ceiling(expectedtotal * 1.0 / size), step);
            Assert.AreEqual(expectedtotal, count);
        }
        [TestMethod]
        public void ToListTest()
        {
            object obj = null;
            var listedObj=obj.ToList();
            Assert.AreEqual(1, listedObj.Count);
            Assert.AreEqual(obj, listedObj.First());
        }
    }
}
